﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Kooboo.Web.Areas.Commerce.Binders;
using Kooboo.Commerce;

using Kooboo.IoC;

namespace Kooboo.Web.Binder
{
    public class ProductQuestionBinder:EntityBinder
    {
        protected override string[] SkipProperties
        {
            get
            {
                return new string[] { "Product" };
            }
        }

        protected override object CreateModel(System.Web.Mvc.ControllerContext controllerContext, System.Web.Mvc.ModelBindingContext bindingContext, Type modelType)
        {
            var model = ObjectContainer.CreateInstance<IProductQuestion>();

            var form = controllerContext.HttpContext.Request;
            

            int productid ;

            if (int.TryParse(form["Product.Id"], out productid))
            {
                var product = ObjectContainer.CreateInstance<IProduct>();
                product.Id = productid;

                model.Product = product;

            }

            return model;
        }
    }
}